
//ts 联合类型 union
//keyof 可以把一个接口对象转换为数组
// //interface Todo {
//     title: string
//     description: string
//     completed: boolean
//   } ----> title ['title','description','completed']

//extends 约束title 依次对比['title','description','completed']是否存在
  
type MyPick<T, K extends keyof T> = {
    [P in K] : T[P]
}

//js
//对比学习

function myPick (todo,keys){
    const obj = {

    }
    keys.forEach(key => {
        if (key in todo){
            obj[key] = todo[key];
        }
        
    });

    return obj;
}

//1.返回一个对象
//2.遍历foreach mapped
//https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#handbook-content
//3.todo[key]取值 indexed
//4.看看key在不在todo里面
// 1.keyof lookup
// 2.extends Generic Constraints 约束

